<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>会员信息</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
    <style type="text/css">
			table th{
				text-align: center;
	            white-space: nowrap;
	        }
			table td{
				text-align: center;
	            white-space: nowrap;
	        }
		    table{
		         empty-cells:show; 
		         border-collapse: collapse;
		         margin:0 auto;
		    }
 			.col-lg-9 {
			    width: 100%;
			}
			.pcc{
				width: 110px;
				height: 34px;
				text-align: center;
				border-color:#ccc;
			}
			input{
				text-indent:10px;
				width: 80%;
				border-radius:5px;
			}
			.search-btnn {
			    float: left;
			     width: 80px; 
			    margin-left: 5px;
			}
		</style>
</head>
<body>


<div id="wrapper">
  <c:if test="${VipPower==0}"> 
	<div id="page-wrapper" style="text-align:center;font-size: 18px ;">
    	<span style="padding-top: 400px;position: absolute;">您没该相关权限！</span>
    </div>
  </c:if>
 <c:if test="${VipPower==1 }">

		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">会员信息</h1>
			</div>
		</div>
		<!-- 搜索框 -->
		<div class="row">
			<div class="col-lg-offset col-lg-9">
				<label class="search-label">会员手机号：</label><input type="text" id="sPhone" value="" placeholder="手机号" class="form-control search-input width200" maxlength="21">
				<label class="search-label">会员卡号：</label><input type="text" id="sCard" value="" placeholder="请输入会员卡号" class="form-control search-input width200" maxlength="21">
				<label class="search-label">分公司：</label>
					<select id="sStore" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%">
						<c:forEach items="${storeList }" var="seller">
							<option value="${seller.storeid }">${seller.title }</option>
						</c:forEach>
					</select>
				   <label class="search-label">营业部：</label>
					<select id="sDao" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%" >
					</select>
	<!-- 		    <label class=" control-label" style="margin-left: 25px;">地址：</label>
			    <div style="display: inline-block;">
				    <select name="province" id="Sprovince" class="pcc" required></select>
					<select name="city" id="Scity" class="pcc" required></select>
					<select name="area" id="Sarea" class="pcc" required></select>
			    </div> -->
				<div class="clearfix"></div>
			</div>
			<!-- <div class="form-group" style="margin-bottom: 7px;margin-left: 25px;">
			   <label class="search-label">营业部：</label>
					<select id="sDao" class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%" >
					</select>
			    <label class=" control-label" style="margin-left: 25px;">地址：</label>
			    <div style="display: inline-block;">
				    <select name="province" id="Sprovince" class="pcc" required></select>
					<select name="city" id="Scity" class="pcc" required></select>
					<select name="area" id="Sarea" class="pcc" required></select>
			    </div>
		    </div> -->
			<div class="col-lg-offset col-lg-9">
				 <label class="search-label">办卡日期：</label><input type="text" id="beginDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				 <label class="search-label">至</label><input type="text" id="endDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">会员生日：</label><input type="text" id="sBeginDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">至</label><input type="text" id="sEndDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">会员状态：</label>
				<div class="search-input">
					<select id="sState" class="selectpicker" multiple="multiple" data-width="150">
						<option value="1">未登录</option>
						<option value="2">未注册</option>
						<option value="3">会员</option>
					</select>
				</div>
				<div class="clearfix"></div>
			</div>
			<div class="col-lg-offset col-lg-9">
			
				 <div class="search-input">
					 <label class="search-label">等级：</label>
					<select id="sTaici" class="selectpicker" multiple="multiple" data-width="150">
						<option value="1">会员</option>
						<option value="2">黄金</option>
						<option value="3">白金</option>
						<option value="4">经纪人</option>
						<option value="5">营业部</option>
						<option value="6">分公司</option>
					</select>
				</div>
			 	 <div class="search-input">
					 <label class="search-label">注册区间：</label>
					<select id="sYz" style="width:150px;height: 34px;"  >
						<option value="0">请选择</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
						<option value="9">9</option>
						<option value="10">10</option>
			
					</select>
				</div>
				<div class="search-input">
					<label class="search-label">到</label>
					<select id="eYz" style="width:150px;height: 34px;">
						<option value="0">请选择</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
						<option value="9">9</option>
						<option value="10">10</option>
			
					</select>
				</div>
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
				<c:if test="${session.userpopedom.busUserSendMessage==1}">
				<button class="btn btn-success search-btnn" onclick="sendMessage();">选择推送</button>
				<button class="btn btn-success search-btnn" onclick="sendAllMessage();">全部推送</button>
				</c:if>
				<div class="clearfix"></div>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
				<div class="row">
					<div>
						<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
						<c:if test="${session.userpopedom.busUserDoExcel==1}">
						<button onclick="doExcel();"  class="btn btn-success pull-right">导出</button>
						</c:if>
					</div>
				</div>
				<div class="table-responsive panel panel-default" >
					<table id="dataTable" class="table table-hover table-bordered" style="overflow:scroll;">
			            <thead>
			               	<tr>
			               		<th width="50px;"></th>
								<th width="200px;">会员卡号</th>
								<th width="100px;">会员姓名</th>
								<th width="200px;">会员手机号</th>
								<th width="200px;">所属分公司</th>
								<th width="100px;">营业部</th>
								<th width="150px;">办卡日期</th>
								
								<th width="150px;">会员生日</th>
								<th width="100px;">会员状态</th>
								<th width="100px;">等级</th>
								<th width="150px;">升级日期</th>
							
								<th width="120px;">线上消费次数</th>
								
							
								<th width="100px;">操作</th>
							</tr>
			            </thead>
			            <tbody id="dataList"></tbody>
			        </table>
				</div>
		        <div class="row">
		        	<div class="col-lg-12">
		        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
		        	</div>
		        </div>
			</div>
		</div>

 </c:if>
	
</div>

<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
		{{each list as item}}
				 <tr id="item{{item.id}}" data-id="{{item.id}}">
					<td><input type="checkbox" name="check_name" value="{{item.phone}}" style="height:20px;"></td>
				 	<td>{{item.card}}</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
                    <td>{{item.storeName }}</td>
					<td>{{item.toBossOneId}}</td>
					<td>{{item.createDate}}</td>
					<td>{{item.birthday}}</td>
					<td>{{item.state | flagTransform:1,'未登录',2,'未注册',3,'会员'}}</td>
					<td>{{item.taici | flagTransform:1,'会员',2,'黄金',3,'白金',4,'经纪人',5,'营业部',6,'分公司'}}</td>
					<td>{{item.babythday}}</td>
				
					<td style="color: #33a6dc;" onclick="convert({{item.id}},{{item.countnum}})">{{item.countnum}}</td>
					
					<td>
						<a href="javascript:showUser('{{item.id}}');"><span class="btn">详情</span></a>
					</td>
				</tr>
		{{/each}}
</script>
<script src="${BASE_PATH}/static/js/PCASClass.js" type="text/javascript"></script>
<script type="text/javascript">
var dataPaginator;
// new PCAS("province","city","area","河南省");//省市县三急联动调用
$(query);
function query(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val(),sYz=$("#sYz").val(),eYz=$("#eYz").val();
// 	 var province=$("#Sprovince").val(),city=$("#Scity").val(),area=$("#Sarea").val();
	 //地址筛选拼接
// 	 var address=province+city+area;
	 var daos="",stores="",taicis="",states="";
		if(store !=null && store !="" && store !=undefined){
			stores=store.join("','");
		}
		if(dao !=null && dao !="" && dao !=undefined){
			daos=dao.join("','");
		}
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	 var params = {
		pageSize:10,
		phone:phone,
		card:card,
		sBeginDate:sBeginDate,
		sEndDate:sEndDate,
		beginDate:beginDate,
		endDate:endDate,
// 	    address:address,
		store:stores,
		dao:daos,
		taici:taicis,
		state:states,
		sYz:sYz,
		eYz:eYz
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/bus/user/page",params,function(result){
		
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
		
	});
}
function reset(){
	$("#sPhone").val("");$("#sCard").val("");$("#sBeginDate").val("");$("#sEndDate").val("");$("#beginDate").val("");$("#endDate").val("");
	$("#sStore").val("");$("#sStore").trigger("change");$("#sDao").val("");$("#sDao").trigger("change");$("#sTaici").val("");$("#sTaici").trigger("change");
	$("#sState").val("");$("#sState").trigger("change");
	$("#sYz").val("0");$("#sYz").trigger("change");$("#eYz").val("0");$("#eYz").trigger("change");
	$("#sStore").selectpicker("refresh"); $("#sDao").selectpicker("refresh");$("#sState").selectpicker("refresh"); $("#sTaici").selectpicker("refresh");
}

var messageDialog;
function sendMessage(){
	var adIds = "";  
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(0==i){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
  		 messageDialog=Kit.dialog("消息推送","${BASE_PATH}/bus/user/sendMessage/"+adIds,{size:'size-wide',closable:true}).open();
}
function sendAllMessage(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val(),sYz=$("#sYz").val(),eYz=$("#eYz").val();
	 var daos="",stores="",taicis="",states="";
		if(store !=null && store !="" && store !=undefined){
			stores=store.join("','");
		}/*else{
			alert("请选择分公司");return;
		}*/
		if(dao !=null && dao !="" && dao !=undefined){
			daos=dao.join("','");
		}
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	 messageDialog=Kit.dialog("消息推送","${BASE_PATH}/bus/user/message?phone="+phone+"&beginDate="+beginDate+"&endDate="
			+endDate+"&card="+card+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&store="+stores+"&dao="
			+daos+"&taici="+taicis+"&state="+states+"&sYz="+sYz+"&eYz="+eYz,{size:'size-wide',closable:true}).open();
}
var showDialog;
function showUser(id){
	showDialog = Kit.dialog("会员详情信息","${BASE_PATH}/bus/user/detail/"+id,{size:'size-wide',closable:true}).open();
}
function onEditSuccess(newObject){
	$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
}
/**
 * 导出
 */
function doExcel(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val(),sYz=$("#sYz").val(),eYz=$("#eYz").val();
// 	 var province=$("#Sprovince").val(),city=$("#Scity").val(),area=$("#Sarea").val();
	 //地址筛选拼接
// 	 var address=province+city+area; 
	 var daos="",stores="",taicis="",states="";
		if(store !=null && store !="" && store !=undefined){
			stores=store.join("','");
		}else{
			stores="";
		}
		if(dao !=null && dao !="" && dao !=undefined){
			daos=dao.join("','");
		}
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	window.location.href="${BASE_PATH}/bus/user/doExcel?phone="+phone+"&beginDate="+beginDate+"&endDate="
			+endDate+"&card="+card+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&store="+stores+"&dao="
			+daos+"&taici="+taicis+"&state="+states+"&sYz="+sYz+"&eYz="+eYz;
	
}
 
$("#sBeginDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    pickerPosition:'bottom-right',
    autoclose:true,
}).on("click",function(){
	var d2=new Date();
	var d=$("#sEndDate").val();
	if(d==""){
		 $("#sBeginDate").datetimepicker("setEndDate",d2);
	}else{
		var d1=new Date(d); 
		d1.setDate(d1.getDate()-1);
		if(d1>d2){
	  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			 $("#sBeginDate").datetimepicker("setEndDate",d1);
		}
	}
});

$("#sEndDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    autoclose:true,
	}).on("click",function(){
		var d=$("#sBeginDate").val();
		var d1=new Date(d); 
		d1.setDate(d1.getDate()+1); 
		$("#sEndDate").datetimepicker("setStartDate",d1);
	});
	
 $(document).on("click","#sEndDate",function(){
    	$('#sEndDate').datetimepicker('show');
    });

$(document).on("click","#sBeginDate",function(){
	$('#sBeginDate').datetimepicker('show');
});
$("#beginDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    pickerPosition:'bottom-right',
    autoclose:true,
}).on("click",function(){
	var d2=new Date();
	var d=$("#endDate").val();
	if(d==""){
		 $("#beginDate").datetimepicker("setEndDate",d2);
	}else{
		var d1=new Date(d); 
		d1.setDate(d1.getDate()-1);
		if(d1>d2){
	  	 	 $("#beginDate").datetimepicker("setEndDate",d2);
		}else{
			 $("#beginDate").datetimepicker("setEndDate",d1);
		}
	}
});

$("#endDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    autoclose:true,
	}).on("click",function(){
		var d=$("#beginDate").val();
		var d1=new Date(d); 
		d1.setDate(d1.getDate()+1); 
		$("#endDate").datetimepicker("setStartDate",d1);
	});
	
 $(document).on("click","#endDate",function(){
    	$('#endDate').datetimepicker('show');
    });

$(document).on("click","#beginDate",function(){
	$('#beginDate').datetimepicker('show');
});
$("#sStore").change(function(){
	var store=$("#sStore").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseDao",
           data: {"store" : store},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#sDao").empty(); 
               for(var i=0; i<data.object.length;i++){
              	 $("#sDao").append("<option value='"+data.object[i].trueName+"'>"+data.object[i].trueName+"</option>");
               }
               $("#sDao").selectpicker("refresh");
           }
       });
    });
function convert(id,n){
	if(!n){
		return Kit.alert("此会员兑换次数为零");
	}
		location.href="${BASE_PATH}/bus/order/convert?userId="+id;   	
}    
</script>
</body>
</html>